package com.ddwl.data.service;

import com.ddwl.common.constant.DataEnum;
import com.ddwl.common.constant.RedisKey;
import com.ddwl.common.service.RedisService;
import com.ddwl.schema.vo.data.DataTodayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Map;

@Service
public class DataService {

    @Autowired
    private RedisService redisService;

    public DataTodayVo today() {
        DataTodayVo vo = new DataTodayVo();
        Map<String, String> dataMap = redisService.getHashOps().entries(RedisKey.DATA_TODAY_CHART.getKey());
        if (!CollectionUtils.isEmpty(dataMap)) {
            vo.setPayments(new BigDecimal(dataMap.getOrDefault(DataEnum.TodayData.PAYMENTS.name(), "0")));
            vo.setMessages(Integer.valueOf(dataMap.getOrDefault(DataEnum.TodayData.MESSAGES.name(), "0")));
            vo.setRegisters(Integer.valueOf(dataMap.getOrDefault(DataEnum.TodayData.REGISTERS.name(), "0")));
            vo.setOrders(Integer.valueOf(dataMap.getOrDefault(DataEnum.TodayData.ORDERS.name(), "0")));
        }
        return vo;
    }
}
